home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / whdload / src / sources / dosio.i < prev    next >
Encoding:
Text File  |  2000-02-28  |  6.5 KB  |  336 lines

  1.  IFND DOSIO_I
  2. DOSIO_I=1
  3. ;*---------------------------------------------------------------------------
  4. ;  :Author.    Bert Jahn
  5. ;  :Contens.    macros for input/output via dos.library
  6. ;  :EMail.    wepl@kagi.com
  7. ;  :Address.    Franz-Liszt-Straße 16, Rudolstadt, 07404, Germany
  8. ;  :Version.    $Id: dosio.i 1.5 2000/01/16 16:21:26 jah Exp jah $
  9. ;  :History.    30.12.95 separated from WRip.asm
  10. ;        18.01.96 IFD Label replaced by IFD Symbol
  11. ;             because Barfly optimize problems
  12. ;        20.01.96 _CheckBreak separated from Wrip
  13. ;        21.07.97 _FGetS added
  14. ;        09.11.97 _GetS added
  15. ;             _FlushInput added
  16. ;        27.12.99 _PrintLn shortend
  17. ;             _CheckBreak enhanced (nested checks)
  18. ;        13.01.00 _GetKey added
  19. ;  :Requires.    -
  20. ;  :Copyright.    This program is free software; you can redistribute it and/or
  21. ;        modify it under the terms of the GNU General Public License
  22. ;        as published by the Free Software Foundation; either version 2
  23. ;        of the License, or (at your option) any later version.
  24. ;        This program is distributed in the hope that it will be useful,
  25. ;        but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. ;        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  27. ;        GNU General Public License for more details.
  28. ;        You can find the full GNU GPL online at: http://www.gnu.org
  29. ;  :Language.    68000 Assembler
  30. ;  :Translator.    Barfly V1.130
  31. ;---------------------------------------------------------------------------*
  32. *##
  33. *##    dosio.i
  34. *##
  35. *##    _PrintLn    outputs a linefeed
  36. *##    _PrintArgs    outputs formatstring(a0) expanded from argarray(a1)
  37. *##    _PrintInt    outputs a longint (d0)
  38. *##    _Print        outputs a string(a0)
  39. *##    _FlushInput    flushes the input stream
  40. *##    _FlushOutput    flushes the output stream
  41. *##    _CheckBreak    --> true(d0) if ^C was pressed
  42. *##    _FGetS        fh(d1) buffer(d2) buflen(d3) --> buffer(d0)
  43. *##    _GetS        buffer(a0) buflen(d0) --> buffer(d0)
  44. *##    _GetKey        --> key(d0)
  45.  
  46.     dc.b    "$Id: dosio.i 1.5 2000/01/16 16:21:26 jah Exp jah $",10,0
  47.     EVEN
  48.  
  49.         IFND    STRINGS_I
  50.             INCLUDE    strings.i
  51.         ENDC
  52.  
  53. ;----------------------------------------
  54. ; Zeilenschaltung
  55. ; IN :    -
  56. ; OUT :    -
  57.  
  58. PrintLn        MACRO
  59.     IFND    PRINTLN
  60. PRINTLN = 1
  61.         IFND    PRINT
  62.             Print
  63.         ENDC
  64. _PrintLn    lea    (.nl),a0
  65.         bra    _Print
  66. .nl        dc.b    10,0
  67.     ENDC
  68.         ENDM
  69.  
  70. ;----------------------------------------
  71. ; Gibt FormatString gebuffert aus
  72. ; IN :    A0 = CPTR FormatString
  73. ;    A1 = STRUCT Array mit Argumenten
  74. ; OUT :    -
  75.  
  76. PrintArgs    MACRO
  77.     IFND    PRINTARGS
  78. PRINTARGS = 1
  79. _PrintArgs    movem.l    d2/a6,-(a7)
  80.         move.l    a0,d1
  81.         move.l    a1,d2
  82.         move.l    (gl_dosbase,GL),a6
  83.         jsr    (_LVOVPrintf,a6)
  84.         movem.l    (a7)+,d2/a6
  85.         rts
  86.     ENDC
  87.         ENDM
  88.  
  89. ;----------------------------------------
  90. ; Gibt LongInt gebuffert aus
  91. ; IN :    D0 = LONG
  92. ; OUT :    -
  93.  
  94. PrintInt    MACRO
  95.     IFND    PRINTINT
  96. PRINTINT = 1
  97. _PrintInt    clr.l    -(a7)
  98.         move.l    #"%ld"<<8+10,-(a7)
  99.         move.l    a7,a0
  100.         move.l    d0,-(a7)
  101.         move.l    a7,a1
  102.         bsr    _PrintArgs
  103.         add.w    #12,a7
  104.         rts
  105.     ENDC
  106.         ENDM
  107.  
  108. ;----------------------------------------
  109. ; Gibt String gebuffert aus
  110. ; IN :    A0 = CPTR String
  111. ; OUT :    -
  112.  
  113. Print        MACRO
  114.     IFND    PRINT
  115. PRINT = 1
  116.         IFND    PRINTARGS
  117.             PrintArgs
  118.         ENDC
  119.  
  120. _Print        sub.l    a1,a1
  121.         bra    _PrintArgs
  122.     ENDC
  123.         ENDM
  124.  
  125. ;----------------------------------------
  126. ; Löschen der Ausgabepuffer
  127. ; IN :    -
  128. ; OUT :    -
  129.  
  130. FlushOutput    MACRO
  131.     IFND    FLUSHOUTPUT
  132. FLUSHOUTPUT = 1
  133. _FlushOutput    move.l    a6,-(a7)
  134.         move.l    (gl_dosbase,GL),a6
  135.         jsr    (_LVOOutput,a6)
  136.         move.l    d0,d1
  137.         beq    .err
  138.         jsr    (_LVOFlush,a6)
  139. .err        move.l    (a7)+,a6
  140.         rts
  141.     ENDC
  142.         ENDM
  143.  
  144. ;----------------------------------------
  145. ; IN :    -
  146. ; OUT :    -
  147.  
  148. FlushInput    MACRO
  149.     IFND    FLUSHINPUT
  150. FLUSHINPUT = 1
  151. _FlushInput    move.l    a6,-(a7)
  152.         move.l    (gl_dosbase,GL),a6
  153.         jsr    (_LVOInput,a6)
  154.         move.l    d0,d1
  155.         beq    .err
  156.         jsr    (_LVOFlush,a6)
  157. .err        move.l    (a7)+,a6
  158.         rts
  159.     ENDC
  160.         ENDM
  161.  
  162. ;----------------------------------------
  163. ; print string "break"
  164. ; IN :    -
  165. ; OUT :    -
  166.  
  167. PrintBreak    MACRO
  168.     IFND    PRINTBREAK
  169. PRINTBREAK = 1
  170.     IFND    PRINT
  171.         Print
  172.     ENDC
  173. _PrintBreak    lea    (.break),a0
  174.         bra    _Print
  175. .break        dc.b    "*** User Break ***",10,0
  176.         EVEN
  177.     ENDC
  178.         ENDM
  179.  
  180. ;----------------------------------------
  181. ; Check break (CTRL-C)
  182. ; IN :    -
  183. ; OUT :    d0 = BOOL break
  184.  
  185. CheckBreak    MACRO
  186.     IFND    CHECKBREAK
  187. CHECKBREAK=1
  188.     IFND    PRINTBREAK
  189.         PrintBreak
  190.     ENDC
  191. _CheckBreak    move.l    a6,-(a7)
  192.     IFD gl_break
  193.         tst.b    (gl_break,GL)
  194.         bne    .b
  195.     ENDC
  196.         move.l    #SIGBREAKF_CTRL_C,d1
  197.         move.l    (gl_dosbase,GL),a6
  198.         jsr    (_LVOCheckSignal,a6)
  199.         tst.l    d0
  200.         beq    .end
  201.         bsr    _PrintBreak
  202.     IFD gl_break
  203.         st    (gl_break,GL)
  204.     ENDC
  205. .b        moveq    #-1,d0
  206. .end        move.l    (a7)+,a6
  207.         rts
  208.     ENDM
  209.  
  210. ;----------------------------------------
  211. ; get line from file
  212. ; remove all LF,CR,SPACE,TAB from the end of line
  213. ; IN :    D1 = BPTR  fh
  214. ;    D2 = APTR  buffer
  215. ;    D3 = ULONG buffer size
  216. ; OUT :    D0 = ULONG buffer or 0 on error/EOF
  217.  
  218. FGetS    MACRO
  219.     IFND    FGETS
  220. FGETS=1
  221.         IFND    STRLEN
  222.             StrLen
  223.         ENDC
  224. _FGetS        movem.l    d3/a6,-(a7)
  225.         subq.l    #1,d3            ;due a bug in V36/V37
  226.         move.l    (gl_dosbase,GL),a6
  227.         jsr    (_LVOFGets,a6)
  228.         move.l    d0,-(a7)
  229.         beq    .end
  230.     ;remove LF,CR,SPACE,TAB from the end
  231.         move.l    (a7),a0
  232.         bsr    _StrLen
  233. .len        tst.l    d0
  234.         beq    .end
  235.         move.l    (a7),a0
  236.         cmp.b    #10,(-1,a0,d0)        ;LF
  237.         beq    .cut
  238.         cmp.b    #13,(-1,a0,d0)        ;CR
  239.         beq    .cut
  240.         cmp.b    #" ",(-1,a0,d0)        ;SPACE
  241.         beq    .cut
  242.         cmp.b    #"    ",(-1,a0,d0)    ;TAB
  243.         bne    .end
  244. .cut        clr.b    (-1,a0,d0)
  245.         subq.l    #1,d0
  246.         bra    .len
  247. .end        movem.l    (a7)+,d0/d3/a6
  248.         rts
  249.     ENDC
  250.         ENDM
  251.  
  252. ;----------------------------------------
  253. ; get line from stdin
  254. ; remove all LF,CR,SPACE,TAB from the end of line
  255. ; IN :    D0 = ULONG buffer size
  256. ;    A0 = APTR  buffer
  257. ; OUT :    D0 = ULONG buffer or 0 on error/EOF
  258.  
  259. GetS    MACRO
  260.     IFND    GETS
  261. GETS=1
  262.         IFND    FGETS
  263.             FGetS
  264.         ENDC
  265. _GetS        movem.l    d2-d3/a6,-(a7)
  266.         move.l    d0,d3            ;buffer size
  267.         move.l    a0,d2            ;buffer
  268.         move.l    (gl_dosbase,GL),a6
  269.         jsr    (_LVOInput,a6)
  270.         move.l    d0,d1            ;fh
  271.         bsr    _FGetS
  272.         movem.l    (a7)+,_MOVEMREGS
  273.         rts
  274.     ENDC
  275.         ENDM
  276.  
  277. ;----------------------------------------
  278. ; wait for a key pressed
  279. ; IN:    -
  280. ; OUT:    D0 = ULONG input char (155 = CSI!)
  281.  
  282. GetKey    MACRO
  283.     IFND    GETKEY
  284. GETKEY=1
  285.     IFND    PRINTBREAK
  286.         PrintBreak
  287.     ENDC
  288. _GetKey        movem.l    d2-d4/a6,-(a7)
  289.  
  290.         move.l    (gl_stdin,GL),d1
  291.         moveq    #1,d2                ;mode = raw
  292.         move.l    (gl_dosbase,GL),a6
  293.         jsr    (_LVOSetMode,a6)
  294.  
  295.         move.l    (gl_stdin,GL),d1
  296.         clr.l    -(a7)
  297.         move.l    a7,d2
  298.         moveq    #1,d3
  299.         jsr    (_LVORead,a6)
  300.         move.l    (a7)+,d4
  301.         rol.l    #8,d4
  302.         
  303.         bra    .check
  304.  
  305. .flush        move.l    (gl_stdin,GL),d1
  306.         subq.l    #4,a7
  307.         move.l    a7,d2
  308.         moveq    #1,d3
  309.         jsr    (_LVORead,a6)
  310.         addq.l    #4,a7
  311.  
  312. .check        move.l    (gl_stdin,GL),d1
  313.         move.l    #0,d2                ;0 seconds
  314.         jsr    (_LVOWaitForChar,a6)
  315.         tst.l    d0
  316.         bne    .flush
  317.         
  318.         move.l    (gl_stdin,GL),d1
  319.         moveq    #0,d2                ;mode = con
  320.         jsr    (_LVOSetMode,a6)
  321.         
  322.         cmp.b    #3,d4                ;Ctrl-C pressed?
  323.         bne    .end
  324.         bsr    _PrintBreak
  325.  
  326. .end        move.l    d4,d0
  327.         movem.l    (a7)+,_MOVEMREGS
  328.         rts
  329.     ENDC
  330.         ENDM
  331.  
  332. ;----------------------------------------
  333.     
  334.  ENDC
  335.  
  336.